package com.neusoft.elmboot.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.neusoft.elmboot.po.DeliveryAddress;
import com.neusoft.elmboot.service.DeliveryAddressService;
import com.neusoft.elmboot.util.APIResponse;

@RestController
@RequestMapping("/DeliveryAddress")
public class DeliveryAddressController {
	@Autowired
	private DeliveryAddressService deliveryAddressService;

	@GetMapping("/list")
	public APIResponse listDeliveryAddressByUserId(DeliveryAddress deliveryAddress) throws Exception {
		return APIResponse.success(deliveryAddressService.listDeliveryAddressByUserId(deliveryAddress.getUserId()));
	}

	@GetMapping
	public APIResponse getDeliveryAddressById(DeliveryAddress deliveryAddress) throws Exception {
		return APIResponse.success(deliveryAddressService.getDeliveryAddressById(deliveryAddress.getDaId()));
	}

	@PostMapping
	public APIResponse saveDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception {
		return APIResponse.success(deliveryAddressService.saveDeliveryAddress(deliveryAddress));
	}

	@PutMapping
	public APIResponse updateDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception {
		return APIResponse.success(deliveryAddressService.updateDeliveryAddress(deliveryAddress));
	}

	@DeleteMapping
	public APIResponse removeDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception {
		return APIResponse.success(deliveryAddressService.removeDeliveryAddress(deliveryAddress.getDaId()));
	}
}